const express = require('express');
const app = express();
const router = require('./02-router');
// body-parser是为post请求的req添加body属性，获得返回的内容
const bodyParser = require('body-parser');
const session = require('express-session');
const port = 8088;
const ip = '127.0.0.1';

app.listen(port,ip,()=>{
    console.log(`服务器已开启，请通过 http://${ip}:${port} 访问`);
});
// 注册静态文件的中间件
app.use('/assets',express.static('assets'));
app.use('/uploads',express.static('uploads'));

// 设置默认模板引擎
app.set('view engine','ejs');

app.use(bodyParser.urlencoded({extended:false}));

//注册session中间件
app.use(session({
    secret : '666',
    resave : false,
    saveUninitialized : true
})); 

// 注册router中间件
app.use(router);